package Demo1;

//标记接口
public class Animal implements Cloneable {
    private String name;
    private int age;
    private String color;

    public Inner inner = new Inner(100);

    public Animal(String name, int age, String color) {
        this.name = name;
        this.age = age;
        this.color = color;
    }



    @Override
    protected Object clone() throws CloneNotSupportedException {
        //整体clone
        Animal temp = (Animal) super.clone();
        //将内部的引用数据类型继续克隆返回
        temp.inner = (Inner)temp.inner.clone();
        return temp;
    }


//    @Override
//    protected Object clone() throws CloneNotSupportedException {
//        return super.clone();
//    }

    @Override
    public String toString() {
        return "Animal{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", color='" + color + '\'' +
                '}';
    }
}
